package admin.forms;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import entities.MetaSeo;


public class MetaSeoForm {
	
	public static TreeMap<String, Object> checkValid(HttpServletRequest request, MetaSeo metaseo) {
		TreeMap<String, Object> form = new TreeMap<String, Object>();
		TreeMap<String, String> check = new TreeMap<String, String>();
		
		String title = (String) request.getParameter("title");
		String keywords = (String) request.getParameter("keywords");
		String description = (String) request.getParameter("description");
		String ogurl = (String) request.getParameter("ogurl");
		String ogimage = (String) request.getParameter("ogimage");
		String titleInfo = (String) request.getParameter("titleInfo");
		String keywordsInfo = (String) request.getParameter("keywordsInfo");
		String descriptionInfo = (String) request.getParameter("descriptionInfo");
		String ogurlInfo = (String) request.getParameter("ogurlInfo");
		
		if (title == null || title.isEmpty()) {
			check.put("title", "Meta Title is not empty!");
			metaseo.setTitle("");
		} else {
			metaseo.setTitle(title);
		}
		
		if (keywords == null || keywords.isEmpty()) {
			check.put("keywords", "Meta Keywords is not empty!");
			metaseo.setKeywords("");
		} else {
			metaseo.setKeywords(keywords);
		}
		
		if (description == null || description.isEmpty()) {
			check.put("description", "Meta Description is not empty!");
			metaseo.setDescription("");
		} else {
		    metaseo.setDescription(description);
		}
		
		if (ogurl != null) {
			metaseo.setOgurl(ogurl);
		}
		
		if (ogimage != null) {
			metaseo.setOgimage(ogimage);
		}
		
		if (titleInfo != null) {
			metaseo.setTitleInfo(titleInfo);
		}
		
		if (keywordsInfo != null) {
			metaseo.setKeywordsInfo(keywordsInfo);
		}
		
		if (descriptionInfo != null) {
			metaseo.setDescriptionInfo(descriptionInfo);
		}
		
		if (ogurlInfo != null) {
			metaseo.setOgurlInfo(ogurlInfo);
		}
		
		
		form.put("checkValid", check);
		form.put("metaseo", metaseo);
		
		return form;
	}
}
